﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 设计模式.原型模式
{
    public class ShapeCache
    {
        private static readonly Dictionary<string, Shape> shapes = new();

        public static Shape GetShape(string shapeId)
        {
            if (!shapes.ContainsKey(shapeId))
            {
                return null;
            }

            Shape shape = shapes[shapeId];
            return (Shape)shape.Clone();
        }

        public static void LoadCache()
        {
            Circle circle = new () { Id = "1" };
            shapes.Add(circle.Id, circle);

            Square square = new() { Id = "2" };
            shapes.Add(square.Id, square);

            Rectangle rectangle = new() { Id = "3" };
            shapes.Add(rectangle.Id, rectangle);
        }
    }
}
